package zj.it.bhne.gridengineeringsurvey.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import zj.it.bhne.gridengineeringsurvey.R;
import zj.it.bhne.gridengineeringsurvey.entity.greendao.Points;

/**
 * BottomActivity中的Twofragment中的本地项目的适配器
 */
public class PoleAdapter extends BaseAdapter {
    private List<Points> list;
    private Context context;

    public PoleAdapter(List<Points> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("InflateParams")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.fragment_pole_adapter, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else
            viewHolder = (ViewHolder) convertView.getTag();
        Points points = list.get(position);
        viewHolder.pole_id.setText(points.getMark());
        viewHolder.pole_type.setText(points.getName());
        viewHolder.pole_lijiu.setText(points.getOld());


        return convertView;
    }

    private static class ViewHolder {
        View rootView;
        TextView pole_id;
        TextView pole_type;
        TextView pole_lijiu;

        ViewHolder(View rootView) {
            this.rootView = rootView;
            this.pole_id = rootView.findViewById(R.id.pole_id);
            this.pole_type = rootView.findViewById(R.id.pole_type);
            this.pole_lijiu = rootView.findViewById(R.id.pole_lijiu);
        }

    }
}
